<template>
	<div class="edit">
		<el-form label-width="80px">
			<el-form-item label="头像">
				<upload-comp
					action="/api/upload?type=user"
					:imgUrl="avatar"
					@res-url="(data) => (avatar = data.resImgUrl)"
				></upload-comp>
				<!-- <el-button type="primary">点击修改头像</el-button> -->
			</el-form-item>
			<el-form-item label="用户名">
				<el-input v-model="name"></el-input>
			</el-form-item>
			<el-form-item label="简介">
				<el-input v-model="sign"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
import UploadComp from '@/components/UploadComp.vue';
import { userEdit } from '@/api/user';
export default {
	components: { UploadComp },
	data() {
		return {
			avatar: this.$store.state.userInfo.avatar,
			name: this.$store.state.userInfo.name,
			sign: this.$store.state.userInfo.sign,
			form: {},
		};
	},
	methods: {
		async save() {
			let data = await userEdit({
				avatar: this.avatar,
				name: this.name,
				sign: this.sign,
			});
			console.log(data);
			if (data.code == 0) {
				this.$router.push({ name: 'userspace' });
			}
			if (data.code == 1) {
				this.$message.error(data.mes);
			}
		},
	},
};
</script>
<style lang="sass" scoped>
.edit
    background-color: #fff
    padding: 20px
</style>